package conteoller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.Document;

import com.google.gson.Gson;
import com.sun.org.apache.bcel.internal.generic.Select;

import biz.ColorBiz;
import biz.GoodsBiz;
import biz.PictureBiz;
import biz.PriceBiz;
import biz.TypeBiz;
import entity.ColortbEntity;
import entity.CustomertbEntity;
import entity.GoodstbEntity;
import entity.PicturetbEntity;
import entity.PricetbEntity;
import entity.TypetbEntity;

/* @Description：
 *       商品servlet，用来处理商品数据
 * @Author: JiangFan
 * @Date: 2019/3/7
 * @Time：12:13
 */
@WebServlet("/GoodsServlet")
public class GoodsServlet extends BaseServlet {
	GoodsBiz gs= new GoodsBiz();//实例化商品biz
	TypeBiz  tb=new TypeBiz();//实例化类别biz
	ColorBiz cB=new ColorBiz();//实例化颜色BIz
	PriceBiz pb=new PriceBiz();//实例化价格biz
	PictureBiz ptb =new PictureBiz();//实例化图片biz
	
	PicturetbEntity pttb= new PicturetbEntity();
	PricetbEntity pricelist =new PricetbEntity(); 
	TypetbEntity ttb =new TypetbEntity();
	ColortbEntity ctb=new ColortbEntity();
	GoodstbEntity gd= new GoodstbEntity();
	
    public String addGoods(HttpServletRequest req, HttpServletResponse resp){

        //取商品信息，并添加
        return "";
    }
    /**
     * 模糊查询商品展示(主页搜索栏)
     * @return 
     */
    public void goodslike (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	// 设置字符集
    	request.setCharacterEncoding("utf-8");
    	String goodsname=request.getParameter("vagu");
    	try {
    		List<GoodstbEntity> list=gs.selgoodsnamelike(goodsname);
            if (list.size()==0) {
				response.getWriter().write("暂时为你查询不到该商品,请重试");
			}
            else {
        			// 存入作用域
        			request.setAttribute("list", list);
        			request.getRequestDispatcher("jsp_wlz/Searchandbelow.jsp").forward(request, response);
				}
    		}
    	 catch (Exception e) {
 			// 将错误消息，存入作用域
 			request.setAttribute("error", e.getMessage());
 			// 跳转到错误页面，显示错误消息
		}
   
}
    /***
     * 
     * 根据商品类别查询商品名以及商品价格以及商品图片
     */
   /* public void goodsall (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	// 设置字符集
    	request.setCharacterEncoding("utf-8");
    	String goodstype=request.getParameter("vagu");
    	try {
    			List<GoodstbEntity> list = gs.selgoodstype(goodstype);//得到商品类
    			String img = ptb.selcolor(goodid);//得到商品图片
    			List<PricetbEntity> listpce = vb.queryver(goodid);//得到版本类
    			List<ColortbEntity> listcol = cb.querycol(goodid);//得到颜色类
    			// 存入作用域
    			request.setAttribute("list", list);
    			request.setAttribute("image", "images_zyx/"+img);
    			request.setAttribute("listver", listver);
    			request.setAttribute("listcol", listcol);
    			request.setAttribute("listcfg", listcfg);
    			request.getRequestDispatcher("purchase.jsp").forward(request, response);
    		} catch (Exception e) {
    			// 将错误消息，存入作用域
    			request.setAttribute("error", e.getMessage());
    			// 跳转到错误页面，显示错误消息
    			
    		}*/

   
}

